package com.generator.storageManage.stockControl.controller;

import com.generator.statics.outboundStatics.pojo.OutCountDetail;
import com.generator.storageManage.stockControl.pojo.KuCun;
import com.generator.storageManage.stockControl.service.impl.StockControlService;
import com.generator.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/StockControl")
public class StockControlAction {

    @Autowired
    private StockControlService stockControlService;

    public StockControlService getStockControlService() {
        return stockControlService;
    }

    public void setStockControlService(StockControlService stockControlService) {
        this.stockControlService = stockControlService;
    }

    //拿到所有的出库记录（分页）
    @ResponseBody
    @RequestMapping("/getKuCunByCondition")
    public PageModel<KuCun> getKuCunByCondition(HttpServletRequest req){
        PageModel<KuCun> outCountObjectPageModel = new PageModel<>();
        String pagenum = req.getParameter("pagenum");
        if(pagenum!=null){
            Integer valueOf = Integer.valueOf(pagenum);
            outCountObjectPageModel.setPageNum(valueOf);
        }
        KuCun kuCun = new KuCun();
        return stockControlService.getKuCunByConditionPage(outCountObjectPageModel, kuCun);
    }

    //查询的出库记录（分页）
    @ResponseBody
    @RequestMapping("/checkStatic")
    public PageModel<KuCun> checkStatic(HttpServletRequest req){
        String storagename = req.getParameter("storagename");
        String brand = req.getParameter("brand");
        String type = req.getParameter("type");
        String productname = req.getParameter("productname");
        KuCun kuCun = new KuCun();
        if(storagename!=""&brand!=""&type!=""&productname!=""){
            kuCun.setStoragename(storagename);
            kuCun.setBrand(brand);
            kuCun.setType(type);
            kuCun.setProduct(productname);
        }else if(storagename!=""&brand==""&type!=""&productname!=""){
            kuCun.setStoragename(storagename);
            kuCun.setType(type);
            kuCun.setProduct(productname);
        }else if(storagename!=""&brand!=""&type==""&productname!=""){
            kuCun.setStoragename(storagename);
            kuCun.setBrand(brand);
            kuCun.setProduct(productname);
        }else if(storagename!=""&brand!=""&type!=""&productname==""){
            kuCun.setStoragename(storagename);
            kuCun.setBrand(brand);
            kuCun.setType(type);
        }else if(storagename!=""&brand==""&type==""&productname!=""){
            kuCun.setStoragename(storagename);
            kuCun.setProduct(productname);
        }else if(storagename!=""&brand!=""&type==""&productname==""){
            kuCun.setStoragename(storagename);
            kuCun.setBrand(brand);
        }else if(storagename!=""&brand==""&type!=""&productname==""){
            kuCun.setStoragename(storagename);
            kuCun.setType(type);
        }else if(storagename!=""&brand==""&type==""&productname==""){
            kuCun.setStoragename(storagename);
        }else if(storagename==""&brand==""&type!=""&productname!=""){
            kuCun.setType(type);
            kuCun.setProduct(productname);
        }else if(storagename==""&brand!=""&type==""&productname!=""){
            kuCun.setBrand(brand);
            kuCun.setProduct(productname);
        }else if(storagename==""&brand!=""&type!=""&productname==""){
            kuCun.setBrand(brand);
            kuCun.setType(type);
        }else if(storagename==""&brand==""&type==""&productname!=""){
            kuCun.setProduct(productname);
        }else if(storagename==""&brand!=""&type==""&productname==""){
            kuCun.setBrand(brand);
        }else if(storagename==""&brand==""&type!=""&productname==""){
            kuCun.setType(type);
        }else if(storagename==""&brand!=""&type!=""&productname!=""){
            kuCun.setBrand(brand);
            kuCun.setType(type);
            kuCun.setProduct(productname);
        }
        PageModel<KuCun> outCountObjectPageModel = new PageModel<>();
        String pagenum = req.getParameter("pagenum");
        if(pagenum!=null){
            Integer valueOf = Integer.valueOf(pagenum);
            outCountObjectPageModel.setPageNum(valueOf);
        }
        return stockControlService.getKuCunByConditionPage(outCountObjectPageModel, kuCun);
    }
}
